<?php
namespace App\Http\Middleware\Auth;

use Closure;
use App\Core\Entity\Session\UserEntity;

/**
 * 用户登录检查
 */
class User
{

    /**
     * 用户实体
     *
     * @var \App\Core\Entity\Session\UserEntity
     */
    protected $user;

    /**
     * 初始化用户实体
     *
     * @param UserEntity $user            
     */
    public function __construct(UserEntity $user)
    {
        $this->user = $user;
    }

    /**
     * 前置 | 后置
     *
     * @param \Illuminate\Http\Request $request            
     * @param \Closure $next            
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        return $this->user->isValid() ? $next($request) : abort(401);
    }
}